home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / main / main.c < prev    next >
C/C++ Source or Header  |  1996-08-01  |  8KB  |  253 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <limits.h>
  4. #include <unistd.h>
  5. #include <syslog.h>
  6. #include "../xconf/xconf.h"
  7. #include "../dnsconf/dnsconf.h"
  8. #include "../netconf/netconf.h"
  9. #include "../askrunlevel/askrunlevel.h"
  10. #include "../userconf/userconf.h"
  11. #include "../fstab/fstab.h"
  12. #include "../mailconf/mailconf.h"
  13. #include "../uucp/uucp.h"
  14. #include "main.h"
  15. #include "main.m"
  16. #include "../translate/translat.h"
  17.  
  18. char *revision = REVISION;
  19.  
  20. /* #Specification: configuration programs / strategy
  21.     The configuration program askrunlevel, netconf, xconf and lpdconf
  22.     share a lot of code. They are seldom used (at startup only)
  23.     generally.
  24.  
  25.     so they have been melted in one program. By using proper symlinks
  26.     this program can behave differently
  27.  
  28.     ln -s /bin/linuxconf /bin/netconf
  29.     ln -s /bin/linuxconf /bin/lpdconf
  30.     ln -s /bin/linuxconf /bin/userconf
  31.     ln -s /bin/linuxconf /bin/fsconf
  32.     ln -s /bin/linuxconf /bin/xconf
  33.     ln -s /bin/linuxconf /sbin/askrunlevel
  34.     ln -s /bin/linuxconf /sbin/fixperm
  35.     ln -s /bin/linuxconf /sbin/dnsconf
  36.     ln -s /bin/linuxconf /sbin/mailconf
  37.     ln -s /bin/linuxconf /sbin/uucpconf
  38.  
  39.  
  40.     This is done mostly to save disk space and also make sure
  41.     all those utility are updated in sync (a single program :-) )
  42. */
  43.  
  44. static HELP_FILE introweb ("main","introweb");
  45.  
  46. /*
  47.     Load the proper messages dictionnary
  48. */
  49. static void main_loaddict ()
  50. {
  51.     /* #Specification: messages dictionnary / location
  52.         The messages dictionnary is normally located in
  53.         /usr/lib/linuxconf/linuxconf-msg-x.y.lang.
  54.         This can't be overriden by the user.
  55.  
  56.         There is a way to override this during development, allowing
  57.         to linuxconf to coexist. The environnement variable "LINUXCONF_DICT"
  58.         contain the path of the directory containing the directories.
  59.  
  60.         This variable is not checked and when the program is run setuid
  61.     */
  62.     const char *basepath = USR_LIB_LINUXCONF;
  63.     if (geteuid() == getuid()){
  64.         char *en = getenv ("LINUXCONF_DICT");
  65.         if (en != NULL) basepath = en;
  66.     }
  67.     /* #Specification: messages & help / langage selection
  68.         The environnement variable LINUXCONF_LANG select the extension
  69.         use to load the messages dictionnay and the help files.
  70.  
  71.         help file will be located in /usr/lib/linuxconf/help.LANG
  72.  
  73.         This mecanism is specific to Linuxconf. This will remain as an
  74.         ultimate override. In the future, linuxconf should be able to
  75.         probe the system to find out which langage to support.
  76.     */
  77.     const char *lang = "eng";
  78.     const char *lang_env = getenv("LINUXCONF_LANG");
  79.     if (lang_env != NULL) lang = lang_env;
  80.  
  81.     char bdict[30];
  82.     sprintf (bdict,"linuxconf-msg-%s.%s",REVISION,lang);
  83.     translat_load (basepath,bdict);
  84.     help_setlang (lang);
  85. }
  86.  
  87. int main (int argc, char *argv[])
  88. {
  89.     int ret = -1;
  90.     char argv0[PATH_MAX];
  91.     char *pta = argv0;
  92.     char *pt = argv[0];
  93.     main_loaddict();
  94.     // Extract the name of the program from its path
  95.     while (*pt != '\0'){
  96.         if (*pt == '/'){
  97.             pt++;
  98.             pta = argv0;
  99.         }else{
  100.             *pta++ = *pt++;
  101.         }
  102.     }
  103.     *pta = '\0';
  104.     /* #Specification: linuxconf / aliases
  105.         linuxconf manipulate of lot of stuff for configuring properly
  106.         a Linux station. Because of this, it include code to perform
  107.         many task normally done by utilities seldom used. It was
  108.         decide that in order to save some disk space, linuxconf could
  109.         act as clone for those different programs. Here is the list
  110.         of the different aliases.
  111.  
  112.         #
  113.         /bin/fsconf
  114.         /bin/linuxconf
  115.         /bin/netconf
  116.         /bin/userconf
  117.         /bin/xconf
  118.         /bin/hostname
  119.         /bin/passwd
  120.         /bin/domainname
  121.         /bin/dnsdomainname
  122.         /sbin/askrunlevel
  123.         /sbin/dnsconf
  124.         /sbin/fixperm
  125.         /sbin/mailconf
  126.         #
  127.     */
  128.     module_load();
  129.     if (strcmp(argv0,"askrunlevel")==0){
  130.         if (getuid()!=0){
  131.             xconf_error (MSG_U(ERR_BOOT,"Askrunlevel is only used\n"
  132.                 "at boot time\n"));
  133.         }else{
  134.             ret = askrunlevel_main (argc, argv);
  135.         }
  136.     }else if (strcmp(argv0,"domainname")==0){
  137.         ret = netconf_domainname (argc,argv);
  138.     }else if (strcmp(argv0,"dnsdomainname")==0){
  139.         ret = netconf_dnsdomainname (argc,argv);
  140.     }else if (strcmp(argv0,"hostname")==0){
  141.         ret = netconf_hostname (argc,argv);
  142.     }else if (strcmp(argv0,"fixperm")==0){
  143.         ret = fstab_fixperm (argc,argv);
  144.     }else if (strcmp(argv0,"dnsconf")==0){
  145.         ret = dnsconf_main (argc,argv);
  146.     }else if (strcmp(argv0,"mailconf")==0){
  147.         ret = mailconf_main (argc,argv);
  148.     }else if (strcmp(argv0,"uucpconf")==0){
  149.         ret = uucp_main (argc,argv);
  150.     }else if (strcmp(argv0,"linuxconf")==0){
  151.         if (argc == 2 && strcmp(argv[1],"--helpfile")==0){
  152.             helpf_checkall();
  153.         }else if (argc == 2 && strcmp(argv[1],"--update")==0){
  154.             netconf_update();
  155.         }else if (argc == 2 && strcmp(argv[1],"--status")==0){
  156.             netconf_status();
  157.         }else if (argc >= 2
  158.             && (strcmp(argv[1],"--http")==0 || strcmp(argv[1],"--demo")==0)){
  159.             /* #Specification: linuxconf / command line / --http
  160.                 The --http option of linuxconf tells it
  161.                 to behave like an httpd server. It will
  162.                 all of a sudden start talking ... html.
  163.  
  164.                 This option is normally used when starting
  165.                 linuxconf from /etc/inetd.conf
  166.  
  167.                 Suboptions are available (--http --options ...)
  168.  
  169.                 #
  170.                 --port port_number: Use this portnumber to format URLs.
  171.                     Default to LINUXCONF_HTTP_PORT
  172.                 --name name: Use this name to format URLs. Default to the
  173.                     fully qualified hostname.
  174.                 --debug 0|1: Assume standalone startup (Not from inetd)
  175.                     and use a different port (LINUXCONF_HTTP_PORT_DEBUG).
  176.                     This way, gdb can be used on linuxconf without problem.
  177.                 #
  178.  
  179.                 The --debug option is maybe useless. If linuxconf detect
  180.                 that the handle 0 is a tty, it assumes it is starting
  181.                 from a command line (not inetd) so assume the same context
  182.                 as debug mode and use the same port.
  183.             */
  184.             /* #Specification: Linuxconf / startting from inetd
  185.                 Here is the proper configuration line which
  186.                 must be added to /etc/inetd.conf
  187.                 linuxconf  stream  tcp     wait  root    /bin/linuxconf --http
  188.             */
  189.             /* #Specification: linuxconf / command line / --demo
  190.                 The --demo option of linuxconf is like the --http
  191.                 except linuxconf will do a chroot("/demo_linuxconf")
  192.                 and will not do anything except probing the system.
  193.                 The mode "simul" on all the time
  194.             */
  195.             if(strcmp(argv[1],"--demo")==0){
  196.                 simul_setdemoflag (1);
  197.                 if (chroot("/demo_linuxconf")==-1
  198.                     || chdir ("/") == -1){
  199.                     openlog ("linuxconf",LOG_PID,LOG_DAEMON);
  200.                     syslog (LOG_ERR,MSG_U(E_DEMOINIT,"can't chroot(\"/demo_linuxconf\" (%m)"));
  201.                     exit (-1);
  202.                 }
  203.             }
  204.             dialog_setmode (DIALOG_HTML);
  205.             int port = -1;
  206.             THISHOST host;
  207.             const char *name = host.getname1();
  208.             int debug = 0;
  209.             for (int i=2; i<argc; i += 2){
  210.                 const char *arg = argv[i+1];
  211.                 if (strcmp(argv[i],"--port")==0){
  212.                     port = atoi(arg);
  213.                 }else if (strcmp(argv[i],"--name")==0){
  214.                     name = arg;
  215.                 }else if (strcmp(argv[i],"--debug")==0){
  216.                     debug = atoi(arg);
  217.                     if (port == -1) port = LINUXCONF_HTTP_PORT_DEBUG;
  218.                 }
  219.             }
  220.             if (isatty(0)){
  221.                 debug = 1;
  222.                 if (port == -1) port = LINUXCONF_HTTP_PORT_DEBUG;
  223.             }                
  224.             if (port == -1) port = LINUXCONF_HTTP_PORT;
  225.             html_sethost (name,port);
  226.             perm_sethtml (1);
  227.             while (html_get(debug,introweb) != -1){
  228.                 linuxconf_main (1);
  229.             }
  230.             printf ("Ending html\n");
  231.         }else{
  232.             linuxconf_main (0);
  233.         }
  234.         ret = 0;
  235.     }else if (strcmp(argv0,"netconf")==0){
  236.         ret = netconf_main (argc, argv);
  237.     }else if (strcmp(argv0,"passwd")==0){
  238.         ret = userconf_passwd (argc,argv);
  239.     }else if (strcmp(argv0,"userconf")==0){
  240.         ret = userconf_main (argc,argv);
  241.     }else if (strcmp(argv0,"fsconf")==0){
  242.         ret = fstab_main (argc,argv);
  243.     }else if (strcmp(argv0,"xconf")==0){
  244.         ret = xconf_main (argc, argv);
  245.     }else{
  246.         fprintf (stderr
  247.             ,MSG_U(ERR_NAME,"This program can't be rename to any name\n"
  248.             "It is normally named linuxconf.\n"));
  249.     }
  250.     return ret;
  251. }
  252.  
  253.